//
//  LDTAVManager.m
//  EPA
//
//  Created by lanou3g on 16/4/21.
//  Copyright © 2016年 浮夸. All rights reserved.
//

#import "LDTAVManager.h"

@interface LDTAVManager ()

@property(nonatomic,strong)AVPlayer *player;

@end

@implementation LDTAVManager

+ (instancetype)shareManager
{
    static LDTAVManager *manager =nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        if (manager == nil) {
            manager = [LDTAVManager new];
            manager.player = [[AVPlayer alloc]init];
        }
    });
    return manager;
}
//播放
- (void)play
{
    AVPlayerItem *item = self.itemArray[self.currentIndex];
    [self.player replaceCurrentItemWithPlayerItem:item];
    [self.player play];
}
//暂停
- (void)pause
{
    [self.player pause];
}
//上一首
- (void)previous
{
    self.currentIndex --;
    if (self.currentIndex < 0) {
        self.currentIndex = self.itemArray.count - 1;
    }
    [self play];
}
//下一首
- (void)next
{
    self.currentIndex ++;
    if (self.currentIndex >= self.itemArray.count) {
        self.currentIndex = 0;
    }
    [self play];
}

//改变进度
- (void)seekToTime:(CMTime)time
{
    [self.player seekToTime:time];
}



@end
